// Copyright (c) 2022 Presto Labs Pte. Ltd.
// Author: daniel

#pragma once

#include <cmath>

namespace impl {

inline int CalculatePrecision(double tick_size) {
  constexpr double buffer = 1.e-15;
  int precision = 0;
  double cur_tick_size = tick_size;
  while (std::abs(cur_tick_size - std::round(cur_tick_size)) > buffer) {
    precision++;
    cur_tick_size = tick_size * std::pow(10, precision);
  }
  return precision;
}

}  // namespace impl
